using System.Collections.Generic;
using I2.Loc;
using UnityEngine;

public class TutCar : TutorialBase
{
	public bool moveToCarComplete;

	public bool getCarComplete;

	public bool chekpointComplete;

	private bool startStepMoveToCar;

	private bool startStepSitCar;

	private bool startStepCheckPoint;

	private bool startCPEnd;

	private bool canGetCar;

	private bool justStopCar;

	public GameObject objPointMoveCar;

	public TutorialCheckpoint chekpointGetCar;

	public List<TutorialCheckpoint> chekpointRotateCarRight;

	public List<TutorialCheckpoint> chekpointRotateCarLeft;

	public TutorialCheckpoint chekpointRotateCarEnd;

	public List<TutorialCheckpoint> listCheckPoint = new List<TutorialCheckpoint>();

	private PointerPanel pointer;

	private TutorialCheckpoint prevCheckpoint;

	public BtnTypeControlCar tutCarControls;

	private bool checkPointEnabled;

	private void Awake()
	{
		if (TutorialManager.instance != null)
		{
			TutorialManager.instance.GetTutorialButtonById(TutorialButtonId.sitInCar).gameObject.AddComponent<ButtonFlicker>();
		}
	}

	public override void OnStart()
	{
		BCWDebug.Log("OnStart TutCar");
		isStarted = true;
		base.gameObject.SetActive(true);
		TutorialCollider.instance.curCollider = TutorialCollider.TypeCollider.Start;
		TutorialManager.instance.car.transform.localPosition = Vector3.zero;
		pointer = PointerController.instance.AddPointer(TutorialManager.instance.car.transform, 0f, null, false);
		TutorialManager.instance.GetTutorialButtonById(TutorialButtonId.shoot).gameObject.SetActive(false);
		TutorialManager.instance.SetActiveButtonId(TutorialButtonId.switchWeapon, false);
		GameController.instance.playerScript.weaponManager.switchWeapon("melee", "knuckles", string.Empty);
		TutorialManager.instance.stepTutorialForFlurry = "8 car";
	}

	public override void OnStop()
	{
		HideText();
		PlayerBehavior.MyPlayer.currentCar.GetComponent<EngineSound>().Stop();
		base.OnStop();
	}

	public override void OnUpdate()
	{
		if (!getCarComplete)
		{
			if (GameController.instance.playerScript.areaBehavior.nearCar == null || !GameTopWindow.instance.buttonGetInCar.activeInHierarchy)
			{
				canGetCar = false;
			}
			else
			{
				canGetCar = true;
			}
			if (canGetCar || PlayerBehavior.MyPlayer.inCar)
			{
				chekpointGetCar.OtklCheckPoint();
				StepSitCar();
			}
			else
			{
				chekpointGetCar.VklCheckPoint();
				StepMoveToCar();
			}
		}
		else
		{
			StepCheckPoint();
			chekpointComplete = true;
			foreach (TutorialCheckpoint item in listCheckPoint)
			{
				if (!item.isActive)
				{
					chekpointComplete = false;
					break;
				}
			}
		}
		if (chekpointComplete && !IsInvoking("OnComplete"))
		{
			TutorialManager.instance.StopAnimAllButton();
			foreach (TutorialButton item2 in TutorialManager.instance.listTutButton)
			{
				item2.SetActive(false);
			}
			GameController.instance.playerScript.currentCar.ActivateCar(false);
			ShowText(ScriptLocalization.Get("Tutorial/src_Tutorial_Car_Psycho"), 0f, true);
			Invoke("OnComplete", 8f);
			Invoke("ShowWeaponMessage", 4f);
		}
		if (chekpointComplete && IsInvoking("OnComplete") && PlayerBehavior.MyPlayer.currentCar.isStopDrive && !justStopCar)
		{
			PlayerBehavior.MyPlayer.currentCar.GetComponent<EngineSound>().Stop();
			justStopCar = true;
		}
	}

	private void ShowWeaponMessage()
	{
		ShowText(ScriptLocalization.Get("Tutorial/src_Tutorial_Get_Weapon"), 0f, true);
	}

	private void StepMoveToCar()
	{
		if (!startStepMoveToCar)
		{
			ShowText(ScriptLocalization.Get("Tutorial/src_Tutorial_Car_ComeClose"), 0f, true);
			startStepMoveToCar = true;
			startStepSitCar = false;
			startStepCheckPoint = false;
			TutorialManager.instance.StopAnimAllButton();
			TutorialManager.instance.SetActiveButtonId(TutorialButtonId.sitInCar, false);
		}
	}

	private void StepSitCar()
	{
		if (GameController.instance.playerScript.inCar)
		{
			TutorialManager.instance.tony.gameObject.SetActive(false);
			objPointMoveCar.SetActive(true);
			getCarComplete = true;
			PointerController.instance.RemovePointer(pointer);
			HideText();
			TutorialManager.instance.StopAnimAllButton();
			TutorialManager.instance.carControlsSelected = true;
			TutorialManager.instance.carArrows.SetActive(true);
			TutorialManager.instance.carPointCollider.SetActive(false);
		}
		else if (!startStepSitCar)
		{
			HideText();
			startStepSitCar = true;
			startStepCheckPoint = false;
			startStepMoveToCar = false;
			TutorialManager.instance.PlayAnimButton(TutorialButtonId.sitInCar);
		}
	}

	private void CarTut_Forward_Buttons()
	{
		Debug.Log("CarTut_Forward_Buttons");
		TutorialCollider.instance.curCollider = TutorialCollider.TypeCollider.Car;
		startStepCheckPoint = true;
		getCarComplete = true;
		objPointMoveCar.SetActive(true);
		ShowText(ScriptLocalization.Get("Tutorial/src_Tutorial_Car_GasToMove"), 100000f);
		TutorialManager.instance.SetActiveButtonId(TutorialButtonId.carButtonControll, true);
		TutorialManager.instance.SetActiveButtonId(TutorialButtonId.carJoystickControll, false);
		TutorialManager.instance.SetActiveButtonId(TutorialButtonId.carGyroscopeControll, false);
		TutorialManager.instance.SetActiveButtonId(TutorialButtonId.carForwardAlt, true);
		TutorialManager.instance.PlayAnimButton(TutorialButtonId.carForwardAlt, TutorialManager.instance.animBtnTapShoot);
		TutorialManager.instance.SetActiveButtonId(TutorialButtonId.carBackwardAlt, true);
		TutorialManager.instance.SetActiveButtonId(TutorialButtonId.carRight, true);
		TutorialManager.instance.SetActiveButtonId(TutorialButtonId.carLeft, true);
	}

	private void CarTut_Forward_Wheel()
	{
		TutorialCollider.instance.curCollider = TutorialCollider.TypeCollider.Car;
		startStepCheckPoint = true;
		getCarComplete = true;
		objPointMoveCar.SetActive(true);
		ShowText(ScriptLocalization.Get("Tutorial/src_Tutorial_Car_JoyMove"), 100000f);
		TutorialManager.instance.SetActiveButtonId(TutorialButtonId.carJoystickControll, true);
		TutorialManager.instance.SetActiveButtonId(TutorialButtonId.carButtonControll, false);
		TutorialManager.instance.SetActiveButtonId(TutorialButtonId.carGyroscopeControll, false);
		TutorialManager.instance.SetActiveButtonId(TutorialButtonId.carJoystick, true);
		TutorialManager.instance.SetActiveButtonId(TutorialButtonId.carJoystickJoy, true);
		TutorialManager.instance.PlayAnimButton(TutorialButtonId.carJoystickJoy, TutorialManager.instance.animBtnSwipeFB);
	}

	private void CarTut_Forward_Camera()
	{
		TutorialCollider.instance.curCollider = TutorialCollider.TypeCollider.Car;
		startStepCheckPoint = true;
		getCarComplete = true;
		objPointMoveCar.SetActive(true);
		ShowText(ScriptLocalization.Get("Tutorial/src_Tutorial_Car_GasToMove"), 100000f);
		TutorialManager.instance.SetActiveButtonId(TutorialButtonId.carGyroscopeControll, true);
		TutorialManager.instance.SetActiveButtonId(TutorialButtonId.carJoystickControll, false);
		TutorialManager.instance.SetActiveButtonId(TutorialButtonId.carButtonControll, false);
		TutorialManager.instance.SetActiveButtonId(TutorialButtonId.carGyroscopeForward, true);
		TutorialManager.instance.SetActiveButtonId(TutorialButtonId.carGyroscopeBack, true);
		TutorialManager.instance.SetActiveButtonId(TutorialButtonId.carGyroscopeTurn, true);
		TutorialManager.instance.PlayAnimButton(TutorialButtonId.carGyroscopeForward, TutorialManager.instance.animBtnTap);
	}

	private void CarTut_Right_Buttons()
	{
		ShowText(ScriptLocalization.Get("Tutorial/src_Tutorial_Car_MoveRight"), 100000f);
		TutorialManager.instance.PlayAnimButton(TutorialButtonId.carRight, TutorialManager.instance.animBtnTap);
	}

	private void CarTut_Right_Wheel()
	{
		ShowText(ScriptLocalization.Get("Tutorial/src_Tutorial_Car_JoyRight"), 100000f);
		TutorialManager.instance.PlayAnimButton(TutorialButtonId.carJoystickJoy, TutorialManager.instance.animBtnSwipeRight);
	}

	private void CarTut_Right_Camera()
	{
		ShowText(ScriptLocalization.Get("Tutorial/src_Tutorial_Car_GyroRight"), 100000f);
		TutorialManager.instance.PlayAnimButton(TutorialButtonId.rotate, TutorialManager.instance.animCarGyroRighr);
	}

	private void CarTut_Left_Buttons()
	{
		ShowText(ScriptLocalization.Get("Tutorial/src_Tutorial_Car_MoveLeft"), 100000f);
		TutorialManager.instance.PlayAnimButton(TutorialButtonId.carLeft, TutorialManager.instance.animBtnTap);
	}

	private void CarTut_Left_Wheel()
	{
		ShowText(ScriptLocalization.Get("Tutorial/src_Tutorial_Car_JoyLeft"), 100000f);
		TutorialManager.instance.PlayAnimButton(TutorialButtonId.carJoystickJoy, TutorialManager.instance.animBtnSwipeLeft);
	}

	private void CarTut_Left_Camera()
	{
		ShowText(ScriptLocalization.Get("Tutorial/src_Tutorial_Car_GyroLeft"), 100000f);
		TutorialManager.instance.PlayAnimButton(TutorialButtonId.rotate, TutorialManager.instance.animCarGyroLeft);
	}

	private void CarTut_Brake_Buttons()
	{
		ShowText(ScriptLocalization.Get("Tutorial/src_Tutorial_Car_PullUp"), 100000f);
		TutorialManager.instance.PlayAnimButton(TutorialButtonId.carBackwardAlt, TutorialManager.instance.animBtnTapShoot);
		startCPEnd = true;
	}

	private void CarTut_Brake_Wheel()
	{
		ShowText(ScriptLocalization.Get("Tutorial/src_Tutorial_Car_JoyStop"), 100000f);
		TutorialManager.instance.PlayAnimButton(TutorialButtonId.carJoystickJoy, TutorialManager.instance.animBtnSwipeFB);
		startCPEnd = true;
	}

	private void CarTut_Brake_Camera()
	{
		ShowText(ScriptLocalization.Get("Tutorial/src_Tutorial_Car_PullUp"), 100000f);
		TutorialManager.instance.PlayAnimButton(TutorialButtonId.carGyroscopeBack, TutorialManager.instance.animBtnTap);
		startCPEnd = true;
	}

	private void StepCheckPoint()
	{
		if (!checkPointEnabled)
		{
			listCheckPoint.ForEach(delegate(TutorialCheckpoint checkPoint)
			{
				checkPoint.gameObject.SetActive(true);
			});
			checkPointEnabled = true;
		}
		if (!TutorialManager.instance.carControlsSelected)
		{
			return;
		}
		if (!startStepCheckPoint)
		{
			switch (settings.typeControlerCar)
			{
			case TypeControlCar.button:
				CarTut_Forward_Buttons();
				break;
			case TypeControlCar.wheel:
				CarTut_Forward_Wheel();
				break;
			case TypeControlCar.camera:
				CarTut_Forward_Camera();
				break;
			}
			prevCheckpoint = listCheckPoint[0];
		}
		TutorialCheckpoint curCheckPoint = listCheckPoint.Find((TutorialCheckpoint c) => !c.isActive);
		if (!(prevCheckpoint != curCheckPoint))
		{
			return;
		}
		prevCheckpoint = curCheckPoint;
		HideText();
		TutorialManager.instance.StopAnimAllButton();
		if (curCheckPoint == null)
		{
			return;
		}
		if (chekpointRotateCarRight.Exists((TutorialCheckpoint c) => c == curCheckPoint))
		{
			switch (settings.typeControlerCar)
			{
			case TypeControlCar.button:
				CarTut_Right_Buttons();
				break;
			case TypeControlCar.wheel:
				CarTut_Right_Wheel();
				break;
			case TypeControlCar.camera:
				CarTut_Right_Camera();
				break;
			}
		}
		if (chekpointRotateCarLeft.Exists((TutorialCheckpoint c) => c == curCheckPoint))
		{
			switch (settings.typeControlerCar)
			{
			case TypeControlCar.button:
				CarTut_Left_Buttons();
				break;
			case TypeControlCar.wheel:
				CarTut_Left_Wheel();
				break;
			case TypeControlCar.camera:
				CarTut_Left_Camera();
				break;
			}
		}
		if (chekpointRotateCarEnd.isActive && !startCPEnd)
		{
			switch (settings.typeControlerCar)
			{
			case TypeControlCar.button:
				CarTut_Brake_Buttons();
				break;
			case TypeControlCar.wheel:
				CarTut_Brake_Wheel();
				break;
			case TypeControlCar.camera:
				CarTut_Brake_Camera();
				break;
			}
		}
	}
}
